package game.players.states;

import game.ball.SoccerBall;
import game.players.SoccerPlayer;
import game.players.cpu.opponent.WithBallLeftMovingCPUOpp;
import game.players.cpu.opponent.WithoutBallLeftMovingCPUOpp;
import game.players.cpu.opponent.WithoutBallRightMovingCPUOpp;
import game.players.cpu.opponent.WithoutBallStationaryCPUOpp;

import com.uqbar.vainilla.colissions.CollisionDetector;

public abstract class CPUOppWithoutBall extends WithoutBallCPU {

	public CPUOppWithoutBall(SoccerPlayer player) {
		super(player);
	}
	
	public boolean collidesAgainstBall(SoccerBall ball, SoccerPlayer player) {
		return CollisionDetector.INSTANCE.collidesCircleAgainstRect(
			ball.getX(), ball.getY(), ball.getRatio(),
			player.getX() + player.getFeetWidth(), 
			player.getY() + player.getAppearance().getHeight() - player.getFeetHeight(), 
			player.getFeetWidth(), player.getFeetHeight()
			);
	}
	
	@Override
	protected void changeToStationaryPosition() {
		this.getPlayer().setState(new WithoutBallStationaryCPUOpp(this.getPlayer()));
	}
	
	@Override
	protected void changeToTheRivalArc() {
		this.getPlayer().setState(new WithBallLeftMovingCPUOpp(this.getPlayer(), -this.getPlayer().getMovementSpeed(), 0));
	}
	
	@Override
	protected void changeToTheRivalArcWith(double advancedX, double advancedY) {
		this.getPlayer().setState(new WithoutBallLeftMovingCPUOpp(this.getPlayer(), advancedX, advancedY));
	}
	
	@Override
	protected void changeToRightMoving(double x, double y) {
		this.getPlayer().setState(new WithoutBallRightMovingCPUOpp(this.getPlayer(), x, y));
	}
	
	@Override
	protected void changeToLeftMoving(double advancedX, double advancedY) {
		this.getPlayer().setState(new WithoutBallLeftMovingCPUOpp(this.getPlayer(), advancedX, advancedY));
	}
	
	@Override
	protected boolean goesToTheRivalArc(double x) {
		return x >= 0;
	}

}
